﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

namespace HRdex_Final.Message
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string annsearch = TextBox1.Text;
            formMessege.SelectCommand = "SELECT  formMessegeSender.MessageID, formMessegeSender.Subject, formMessegeSender.DateTime, formMessegeSender.AttachmentName, " +
                      "formMessegeSender.Parent, formEmployees.LastName + ', ' + formEmployees.FirstName AS fulname, catMessege.catMessegeName " +
                      "FROM formMessegeSender INNER JOIN formEmployees ON formMessegeSender.EmployeeID = formEmployees.EmployeeID INNER JOIN " +
                      "catMessege ON formMessegeSender.catMessegeID = catMessege.catMessegeID " +
                      "WHERE (formMessegeSender.fromEmpID = " + SessionID() + ") AND (formMessegeSender.Subject like '%" + annsearch + "%')";
           
        }
        string SessionID()
        {
            return Session["EmployeeNo"].ToString();
        }

        SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\HRdexDB.mdf;Integrated Security=True;User Instance=True");

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string sqlc = "UPDATE formMessegeSender SET  Readed = 1 WHERE MessageID = " + GridView1.SelectedDataKey.Value.ToString();

            SqlCommand cmd = new SqlCommand(sqlc, conn);
            try
            {
                conn.Open();
                cmd.ExecuteNonQuery();
            }
            catch (Exception)
            {

                //throw;
            }
            finally
            {
                conn.Close();
            }

            Session["messageID"] = GridView1.SelectedDataKey.Value.ToString();
            Session["new"] = "1";
            Server.Transfer("~/Message/MessageNew.aspx");
        }
    }
}